package com.qctpos.crm.webapi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qctpos.crm.common.annotation.ResponseResult;
import com.qctpos.crm.common.annotation.UserLoginToken;

import com.qctpos.crm.domain.dto.DemoListDto;
import com.qctpos.crm.domain.dto.PagerQueryDto;
import com.qctpos.crm.domain.entity.Demo1;
import com.qctpos.crm.domain.mapstruct.StructMapper;
import com.qctpos.crm.service.Demo1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@ResponseBody
@Controller
@RequestMapping("/Demo")
@Api(tags = "演示接口")
@UserLoginToken //需要登录 验证token
public class DemoController extends BaseApiController<Demo1Service, Demo1>
{

    @Autowired
    private  Demo1Service baseService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取详情", notes = "根据ID获取详情备注")
    //@ResponseResult//自动封装成Result
    public DemoListDto getById(@PathVariable("id") Long id) throws Exception {
        Demo1 demo1 = baseService.getById((id));
        return StructMapper.INSTANCE.demo1ToDemoListDto(demo1);
    }
    @GetMapping("/pageList")
    @ApiOperation(value = "分页获取", notes = "分页获取备注")
    public IPage<Demo1> GetPagerList(PagerQueryDto input) throws Exception {
        IPage<Demo1> result = baseService.GetPagerList(input);
        return result;
    }

    @GetMapping("/pageXmlList")
    @ApiOperation(value = "XML分页获取", notes = "XML分页获取备注")
    public IPage<DemoListDto> GetPagerXmlList(PagerQueryDto input) throws Exception {
        IPage<DemoListDto> result = baseService.selectDemo1PagerList(input);
        return result;
    }


    @GetMapping("/testTransactional")
    @ApiOperation(value = "测试事务提交", notes = "")
    //@ResponseResult//自动封装成Result
    public void TestTransactional() throws Exception {
        baseService.TestTransactional ();
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增", notes = "新增")
    public  Long add() throws Exception {
        return baseService.SaveData();
    }


}
